<?php 

$basepath = dirname(__FILE__) . "/";

$inc = array('lib','actions','functions');
foreach($inc as $path){
	$handler = opendir($basepath.$path);
	while($file = readdir($handler)){
		if($file[0] != '.' && $file != '..'){
			require_once($basepath."$path/$file");
		}
	}
	closedir($handler);
}

$command = explode(':',$argv[1]);

$working_path = file_exists('.exp') ? true : false;

init();
echo init_message();

$class = strlen($command[0])>0 ? $command[0] : 'NULL';

if($class == 'NULL' || !class_exists($class)){
	echo verbose_message("== Invalid command: $class");
	_exit(0);
}
$method = isset($command[1]) ? $command[1] : '_default';

if(!in_array($method,get_class_methods($class))){
	echo verbose_message("== Invalid method: {$class}:{$method}");
	_exit(0);
}

if("$class.$method"!="create._default" && "$class.$method"!="help._default"){
	if(!$working_path){
		echo verbose_message("== '.' is not an exp project directory.");
		_exit(4);
	}
	$expdb = sqlite_open("./data/expdb", 0666);
	require_once('config.exp');
}

$ex = new $class();
$ex->$method();

if("$class.$method"!="create._default" && $class!="help"){
	sqlite_close($expdb);
}

echo "\n";